package com.cheboohui.iqs.taiping.direct.v;

import com.alibaba.fastjson.JSONObject;
import com.cheboohui.iqs.config.Config;
import com.cheboohui.iqs.taiping.direct.DirectTp;
import com.cheboohui.iqs.taiping.direct.PublicNew;
import com.cheboohui.iqs.taiping.direct.RequestHead;
import com.cheboohui.iqs.taiping.direct.ResTaiPing;

/**
 * V01-推荐方案报价
 * 
 * @author xielonghai
 * @version 2016-07-07
 */
public class V01Request {

	/**
	 * 推荐方案报价接口方法
	 * 
	 * @param session
	 *            会话ID--初始为空,后续调用为上次request返回
	 * @param param
	 *            请求参数json
	 * @return
	 */
	public static ResTaiPing requestV01(String session, JSONObject param) {
		String value = Config.value + ":主接口-推荐方案报价";
		String[] key = { "risk" // 险种信息（risk）
				, "itemKindBZ"// 交强险险别信息（itemKindBZ）
				, "itemKindBS"// 商业险险别信息（itemKindBS）
				, "tax"// 车船税信息（tax）
				, "vehicle"// 车辆信息（vehicle）
				, "vehicleDepJS"// 交管车辆检验码（vehicleDepJS）
		};

		return DirectTp.request(value, PublicNew.REQUEST_URL + "/recommended", getRequest(session, param), key);
	}

	/**
	 * 获取--V01-推荐方案报价------请求参数
	 * 
	 * @param session
	 *            会话ID--初始为空,后续调用为上次request返回
	 * @param param
	 *            请求参数json
	 * @return
	 */
	private static String getRequest(String session, JSONObject param) {
		JSONObject head = RequestHead.getHead(session);
		String request = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
		request = request + "\n" + "<request>";
		request = request + "\n" + "<head>";

		request = request + "\n\t" + "<msgId>" + head.getString("msgId") + "</msgId>";
		request = request + "\n\t" + "<timeStamp>" + head.getString("timeStamp") + "</timeStamp>";
		request = request + "\n\t" + "<session>" + head.getString("session") + "</session>";
		request = request + "\n\t" + "<userCode>" + head.getString("userCode") + "</userCode>";
		request = request + "\n\t" + "<clientName>" + head.getString("clientName") + "</clientName>";

		request = request + "\n" + "</head>";
		request = request + "\n" + "<body>";

		request = request + "\n\t" + "<sales>";
		request = request + "\n\t\t" + "<groupNo>" + param.getString("groupNo") + "</groupNo>";// 团队号
		// request = request + "\n\t\t" + "<solutionCode>" +
		// "0351010601002000040004" + "</solutionCode>";//子协议代码
		// request = request + "\n\t\t" + "<salesmanCode>" +""+
		// "</salesmanCode>";//业务员代码
		request = request + "\n\t" + "</sales>";

		request = request + "\n\t" + "<order>";
		request = request + "\n\t\t" + "<orderNo>" + param.getString("orderNo") + "</orderNo>";// 订单编号
		request = request + "\n\t" + "</order>";

		request = request + "\n\t" + "<risk>";
		request = request + "\n\t\t" + "<riskCode>BS</riskCode>";// 商业险编码
		request = request + "\n\t\t" + "<startDate>" + param.getString("BStime") + "</startDate>";// 保险开始时间
		request = request + "\n\t" + "</risk>";

		request = request + "\n\t" + "<risk>";
		request = request + "\n\t\t" + "<riskCode>BZ</riskCode>";// 交强险编码
		request = request + "\n\t\t" + "<startDate>" + param.getString("BZtime") + "</startDate>";// 保险开始时间
		request = request + "\n\t" + "</risk>";

		request = request + "\n" + "</body>";
		request = request + "\n" + "</request>";
		return request;
	}
}
